'use strict';

const RequestJsonApi = require('../lib/class/requestJsonApi');

module.exports = app => {
  // 定义参数 继承request类

  const host = app.config.apiServiceLocation.member;
  const url = '/users';
  const dataType = 'users';

  const users = new Users({host, url, dataType});

  return users;
};

class Users {
  constructor (options) {
    this.requestJsonApi = new RequestJsonApi(options);
  }

  async index () {
    const data = await this.requestJsonApi.get();
    return data;
  }

  async signIn (unionId, shopId) {
    const attributes = {
      unionId,
      shopId
    };
    const path = '/signIn';
    const successCode = 200;
    const result = await this.requestJsonApi.post(attributes, { path, successCode });
    return result;
  }

  async signUp (openId, nickName, unionId, avatar, shopId) {
    const attributes = {
      openId, nickName, unionId, avatar, shopId
    };

    const result = await this.requestJsonApi.post(attributes);
    return result;
  }

  // async getMenuProducts (shopId) {
  //   // { idList: [1, 3, 5, 6, 7] }
  //   const data = await this.requestJsonApi.get({ filters: { userId: shopId }, pages: { size: 100 }, fields: { products: 'name,logo,prices,productType' } });
  //   return data;
  // }
}
